﻿using DAL;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ViewModels;

namespace BLL
{
    /// <summary>
    /// 借阅业务逻辑类
    /// </summary>
    public class BorrowBLL
    {
        BorrowDAL dal;
        UserVM vm;
        public BorrowBLL()
        {
            dal = new BorrowDAL();
            vm = new UserVM();
        }

        public MemoryStream GetUserPhoto(Guid stuid)
        {
            return dal.GetUserPhoto(stuid);
        }
        public DataSet GetUserBorrowListByID(Guid stuid)
        {
            return dal.GetUserBorrowListByID(stuid);
        }
        public UserVM GetUserInfoByStuNo(string stuno)
        {
            vm = dal.GetUserInfoByStuNo(stuno);
            if (vm != null)
                return dal.GetUserInfoByStuNo(stuno);
            else
                return null;
        }
        public bool GetBookState(string bookid)
        {
            return dal.GetBookState(bookid);
        }
        public bool InsertBorrowList(string bookid,Guid stuid)
        {
            bool result = false;//默认返回结果值，false，不可借
            /// 如果GetBookState返回真值，说明书籍在借，不能继续借阅
            /// 如果GetBookState返回假值，说明书籍在库，可以继续借阅
            if (GetBookState(bookid))
            {
                result = false;
                return result;
            }
            else
            {
                result = dal.InsertBorrowList(bookid, stuid);
                return result;
            }
        }
    }
}
